from django_filters.rest_framework import FilterSet,filters
from home.models import Question
# 自定义搜索工具类
class QuestionFilter(FilterSet):
    # 模糊匹配
    keywords = filters.CharFilter(field_name='title', lookup_expr='icontains')
    # create_time=起始时间,结束时间
    create_time=filters.BaseInFilter(field_name='create_time',lookup_expr='range')
    # filters.RangeFilter(): 仅限于数值类型, 不适用于日期类型
    # 设置排序字段
    # ordering=filters.OrderingFilter(fields=('id','level','create_time'))
    class Meta:
        # 指定数据表模型类
        model = Question
        # 指定搜索字段
        fields = ['cate_id','status']